<!-- 公用的试验痕迹详情页面 -->
<template>
	<div class="testTrace">
		<el-tabs v-model="activeName" type="card" size="small">
			<el-tab-pane label="详细信息" name="first" v-if="firstShow"></el-tab-pane>
			<el-tab-pane label="历史痕迹" name="second"></el-tab-pane>
		</el-tabs>
		<div v-if="activeName == 'first' && formConfig.length > 0 && firstShow">
			<form-index ref="form" :formConfig="formConfig" type="look"> </form-index>
		</div>
		<div v-else>
			<el-collapse v-model="activeNames">
				<el-collapse-item
					:title="
						item.tableMark +
						'\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0操作原因:' +
						item.optReason
					"
					:name="index.toString()"
					v-for="(item, index) in list"
					:key="index.toString()"
				>
					<div v-html="item.changeContent"></div>
				</el-collapse-item>
			</el-collapse>
		</div>
	</div>
</template>

<script>
	import formIndex from "@/components/customComponents/customForm/formIndex"
	import { AjaxCommon } from "@/libs/apiCommon"
	import { PopupCommon } from "@/libs/popupCommon"
	import { RouteForm } from "@/mockData/routeForm"
	export default {
		/*
		 *    keyId
		 */
		props: ["keyId", "routeUrl", "pageParam", "dataVersion"],
		components: { formIndex },
		data() {
			return {
				firstShow: true,
				activeName: "first",
				activeNames: ["0"],
				formConfig: [],
				list: [],
			}
		},
		computed: {},
		created() {},
		methods: {
			initFormJs() {
				const item = RouteForm.find((t) => t.name == this.routeUrl)
				let self = this
				let pageParam = {}
				if (item.formJs) {
					// 这里需要改成加载动态文件
					import("@/assets" + item.formJs)
						.then((res) => {
							pageParam = JSON.parse(self.pageParam)
							let config = []
							Object.keys(res).map((t) => {
								config = res[t]
							})
							Object.keys(pageParam).map((p) => {
								if (config.find((c) => c.fieldName == p)) {
									config.find((c) => c.fieldName == p).filedValue = pageParam[p]
								} else if ("optReason" == p) {
									// 这个暂时加了没用，因为详情页面的操作原因禁用了。
									config.push({
										fieldName: "optReason",
										fieldCNName: "操作原因",
										filedValue: pageParam[p],
										type: "textarea",
									})
								}
							})
							self.formConfig = config
							self.firstShow = true
						})
						.catch((err) => {
							self.firstShow = false
							console.log(err, "22222221.................")
						})
				} else {
					PopupCommon.notify(
						"info",
						"此页面暂未配置formJs，请记录模块名称联系zgq处理"
					)
				}
			},
			// 变更记录
			getList() {
				let self = this
				const pageParam = JSON.parse(self.pageParam)
				console.log(pageParam, self.dataVersion)
				AjaxCommon("/ccdc/common/trance/queryTrances", "post", {
					dv: self.dataVersion,
				}).then((res) => {
					if (res.data.code == 200) {
						let newData = res.data.result.records
						if (newData.length > 0) {
							newData.map((b) => {
								b.changeContent = b.changeContent.replace(/\r\n/g, "<br/>")
								return b
							})
						}
						self.list = newData
					} else {
						PopupCommon.notify("error", res.data.message)
					}
				})
			},
		},
		mounted() {
			this.$nextTick(function () {
				this.initFormJs()
				this.getList()
			})
		},
	}
</script>

<style scoped></style>
